﻿using System;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using Xenta.Operations;
using Xenta.Plugins;
using Xenta.Structs;
using Xenta.Utils;

namespace Xenta.Tests.Operations
{
    [TestFixture]
    public class MessageTemplateTranslationTests : OperationTest
    {
        protected override IEnumerable<Type> ModelMappings
        {
            get
            {
                return NHMappings.ALL;
            }
        }

        protected override IDictionary<DependencyInfo, IDependency> Dependencies
        {
            get
            {
                var components = new Dictionary<DependencyInfo, IDependency>();
                var messageSender = new Mock<IMessageSender>();
                components.Add(new DependencyInfo
                {
                    ID = "52fa95dc-61b3-47b8-af7d-9453d8269d30"
                }, messageSender.Object);
                return components;
            }
        }

        [TestCase("subject", "text")]
        public void Can_CRUD(string subject, string text)
        {
            var t_template = Processor.Execute(new CreateMessageTemplateTranslation
            {
                HolderID = Processor.Execute(new CreateMessageTemplate
                {
                    Code = "xy",
                    SenderID = Guid.Parse("52fa95dc-61b3-47b8-af7d-9453d8269d30")
                }).Result.EntityID,
                LanguageID = Processor.Execute(new CreateLanguage
                {
                    Code = "xy"
                }).Result.EntityID,
                Subject = subject,
                Text = text
            }).Result;

            Assert.NotNull(t_template);
            t_template.Subject.AreEqualIgnoringCase(subject);
            t_template.Text.AreEqualIgnoringCase(text);
            t_template.AreEqual(Processor.Execute(new GetMessageTemplateTranslation
            {
                EntityID = t_template.EntityID
            }).Result);

            subject = subject.Reverse();
            text = text.Reverse();
            var upd_t_template = Processor.Execute(new UpdateMessageTemplateTranslation
            {
                EntityID = t_template.EntityID,
                LanguageID = t_template.Language.EntityID,
                Subject = subject,
                Text = text
            }).Result;

            Assert.NotNull(upd_t_template);
            upd_t_template.AreEqual(t_template);
            upd_t_template.Subject.AreEqualIgnoringCase(subject);
            upd_t_template.Text.AreEqualIgnoringCase(text);

            Processor.Execute(new DeleteMessageTemplateTranslation
            {
                EntityID = t_template.EntityID
            });
        }
    }
}
